package com.lzj.server.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lzj.server.common.service.AttachmentService;
import com.lzj.server.entity.video.VideoLibrary;
import com.lzj.server.service.VideoService;
import com.lzj.server.utils.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotNull;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author Lzj
 * @date 2025/5/26
 * @description 视频基础控制层
 */
@Controller
@RequestMapping("vimi/video-base")
@Tag(name = "视频基本功能模块")
public class VideoBaseController {
    private final VideoService videoService;

    VideoBaseController(VideoService videoService, AttachmentService attachmentService) {
        this.videoService = videoService;
    }

    /**
     * 获取视频详情
     */
    @GetMapping("/get")
    @Validated
    @Operation(summary = "获取详情", description = "根据视频ID获取视频详情")
    public Result<VideoLibrary> get(@Parameter(description = "视频ID", required = true)
                             @NotNull @RequestParam("id") Long id) {
        return Result.success(videoService.getById(id));
    }

    /**
     * 分页查询
     */
    @PostMapping("/list")
    @Operation(summary = "分页查询", description = "分页查询视频列表")
    public Result<IPage<VideoLibrary>> list(@RequestBody VideoLibrary video,
                                            @Parameter(description = "页码", required = true) @RequestParam("page") Integer currentPage,
                                            @Parameter(description = "每页数量", required = true) @RequestParam("size") Integer pageSize) {
        IPage<VideoLibrary> page = new Page<>(currentPage, pageSize);
        return Result.success(videoService.getPageBean(page, video));
    }


    /**
     * 创建or编辑
     */
    @PostMapping("/addOrEdit")
    @Operation(summary = "创建或者编辑", description = "创建或者编辑视频")
    public Result<Boolean> addOrEdit(@RequestBody VideoLibrary video) {
        return Result.success(videoService.addOrEdit(video));
    }


    /**
     * 删除
     */
    @GetMapping("/remove")
    @Operation(summary = "删除", description = "删除视频")
    public Result<Boolean> delete(@Parameter(description = "视频ID", required = true)
                                  @NotNull @RequestParam("id") Long id) {
        return Result.success(videoService.removeById(id));
    }

    /**
     * 查看观看权限
     */
    @GetMapping("/hasViewPermission")
    @Operation(summary = "查看权限", description = "查看视频查看权限")
    public Result<Boolean> hasViewPermission(
            @Parameter(description = "视频ID", required = true)
            @RequestParam("id") Long id) {
        return Result.success(videoService.hasViewPermission(id));
    }

}
